package com.hns.can.base.service;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hns.can.base.entity.SysFuncRegisterEntity;
import com.hns.can.base.vo.MenuVo;
import com.hns.frame.service.CommonService;
import com.hns.tool.pub.PubUtil;
import com.hns.tool.pub.UtilString;

/**
 * 功能service
 * @author:Fisher
 * @email:zhuangcaijin@126.com
 * @version Revision 2.0.0
 */
@Service
public class SysFuncService extends CommonService{
    
    /**
     * 根据用户角色获取功能权限列表
     * @param roleIdList
     * @return  权限列表
     * @author:Fisher
     * @email:zhuangcaijin@126.com
     */
    @SuppressWarnings("unchecked")
    public List<MenuVo> getSysFuncListByRoleList(List<String> roleIdList){
        List<MenuVo> list = PubUtil.convertListMapToObject(
            sqlMapDao.selectList("sysFunc.getSysFuncListByRoleList", roleIdList), MenuVo.class);
        return list;
    }
    
	/**
	 * @author zy
	 * @category 查询功能资源列表
	 * @param entity
	 * @return
	 */
	@SuppressWarnings({"rawtypes", "unchecked" })
    public List getSysFuncList(SysFuncRegisterEntity entity){
		List list = sqlMapDao.selectList("sysFunc.getSysFuncList", entity);
		list = PubUtil.convertListMapToObject(list, SysFuncRegisterEntity.class);
		return list;
	}
	
	/**
	 * @author zy
	 * @category 添加功能资源
	 */
	@Transactional
	public void saveSysFunc(SysFuncRegisterEntity entity){
		//生成id
		entity.setId(UtilString.getUUID());
		commonEntityDao.save(entity);
	}
	/**
	 * @author zy
	 * @category 编辑功能资源
	 */
	@Transactional
	public void updateSysFunc(SysFuncRegisterEntity entity){
		Timestamp timestamp = new Timestamp(new Date().getTime());
		entity.setCreateTs(timestamp);
		commonEntityDao.update(entity);
	}
	
	/**
	 * @author zy
	 * @category 删除功能资源
	 * @param request
	 */
	@Transactional
	public void deleteSysFunc(String[] ids){
		commonEntityDao.delete(SysFuncRegisterEntity.class, ids);
	}
	
	
	/**
     * 根据用户角色获取功能权限列表
     * @param roleIdList
     * @return  权限列表
     * @author:Fisher
     * @email:zhuangcaijin@126.com
     */
    @SuppressWarnings("unchecked")
    public List<MenuVo> getSysFuncListForLog(List<String> roleIdList){
        List<MenuVo> list = PubUtil.convertListMapToObject(
            sqlMapDao.selectList("sysFunc.getSysFuncListForLog", roleIdList), MenuVo.class);
        return list;
    }
}
